<?php

class TableListView {

    private static $me = NULL;

    public static function getInstance() {
        if (!self::$me instanceof TableListView) {
            self::$me = new TableListView();
        }

        return self::$me;
    }

    public function getTableListTemplate($tableIDs) {

        $xtpl = new XTemplate(Utility::getFileContent(DIR_TEMPLATES . DS . 'table.list.main.tpl.html'));
        $rows = '';
        foreach ($tableIDs as $tableID) {
            $rows .= $this->getTableRowTemplate($tableID);
        }
        $xtpl->assign('rows', $rows);

        $xtpl->parse('main');
        return $xtpl->out('main');
    }

    private function getTableRowTemplate($tableID) {
        $xtpl = new XTemplate(Utility::getFileContent(DIR_TEMPLATES . DS . 'table.list.row.tpl.html'));

        $xtpl->assign('table', new Table($tableID));

        $xtpl->assign('rowColor', Utility::getRowColor());

        $xtpl->parse('main');
        return $xtpl->out('main');
    }

    

}
